﻿using System;
using System.Collections.Generic;
using RockCorn.Internals;
using RockCorn.Objects.Moving;

namespace RockCorn.Objects
{
    class ExplodingBlock : Block
    {
        public new const string CollisionGroupString = "exploding block";
        private bool collided = false;

        public ExplodingBlock(MatrixCoords topLeft)
            : base(topLeft)
        {
            this.body = new char[,] { { '*' } };
        }

        public override int GetPoints()
        {
            return 25;
        }

        public override string GetCollisionGroupString()
        {
            return ExplodingBlock.CollisionGroupString;
        }

        public override IEnumerable<GameObject> ProduceObjects()
        {
            if (collided)
            {
                List<GameObject> destroyers = new List<GameObject>();
                this.IsDestroyed = true; ; // self destroy
                // destroy in 8 directions - engine will handle out-of-gamefield objects - diagonals are not working
                destroyers.Add(new DestroyerObject(this.TopLeft, new MatrixCoords(-1, -1)));  // \. top-left
                destroyers.Add(new DestroyerObject(this.TopLeft, new MatrixCoords(-1, 0)));  // |. top-center
                destroyers.Add(new DestroyerObject(this.TopLeft, new MatrixCoords(-1, 1))); // ./ top-right
                destroyers.Add(new DestroyerObject(this.TopLeft, new MatrixCoords(0, -1)));  // -. centerleft
                destroyers.Add(new DestroyerObject(this.TopLeft, new MatrixCoords(0, 1)));  // .- center-right
                destroyers.Add(new DestroyerObject(this.TopLeft, new MatrixCoords(1, -1))); // /^ bottom-left
                destroyers.Add(new DestroyerObject(this.TopLeft, new MatrixCoords(1, 0)));  // |^ bottom-center
                destroyers.Add(new DestroyerObject(this.TopLeft, new MatrixCoords(1, 1)));  // \^ bottom-right
                return destroyers;
            }
            else return new List<GameObject>(); 
        }

        public override void RespondToCollision(CollisionData collisionData)
        {
            this.collided = true;
        }
    }
}
